package com.hualan.controller;

import com.github.pagehelper.PageInfo;
import com.hualan.domain.Heartknowledge;
import com.hualan.service.heartKonwledgeService;
import com.hualan.service.impl.HeartKnowledgeService;
import com.hualan.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/heartKnowledge")
public class HeartKnowledgeController {

    @Autowired
    private HeartKnowledgeService heartKnowledgeService;
    //注入service对象
    @Autowired
    private heartKonwledgeService service;

    @GetMapping("/getAllHeartKnowledge")
    public R getAllHeartKnowledge(){
        return R.success(heartKnowledgeService.findAllHeartKnowledge());
    }

    //查询全部的方法
    @GetMapping("/queryAllList")
    public R getHeartKnowledgeList() {
        return service.queryAllHeartKnowledgeList();
    }
    //查询全部的方法
    @GetMapping("/queryAllListByPage")
    public R queryAllListByPage(@RequestParam(name = "pageNum", defaultValue = "1") int pageNum, @RequestParam(name = "pageSize", defaultValue = "5") int pageSize) {
        PageInfo<Heartknowledge> list = service.queryAllHeartKnowledgeListByPage(pageNum, pageSize);
        return R.success(list);
    }
    //添加的方法
    @PostMapping("/addHeartKnowledge")
    public R addHeartKnowledge(Heartknowledge heartknowledge) {
        return service.addHeartKnowledge(heartknowledge);
    }

    //删除的方法
    @DeleteMapping("/deleteHeartKnowledge")
    public R deleteHeartKnowledge(Integer id) {
        return service.deleteHeartKnowledge(id);
    }

    //修改的方法
    @PostMapping("/updateHeartKnowledge")
    public R updateHeartKnowledge(Heartknowledge heartknowledge) {
        return service.updateHeartKnowledge(heartknowledge);
    }

    //根据名称进行模糊查询的方法
    @PostMapping("/queryHeartKnowledgeByName")
    public R queryHeartKnowledgeByName(String name) {
        return service.queryHeartKnowledgeByName(name);
    }
    //动态修改的sql
    @PostMapping("/updateHeartKnowledgeById")
    public R updateHeartKnowledgeById(Heartknowledge heartknowledge) {
        return service.updateHeartKnowledgeById(heartknowledge);
    }
}
